package cn.crc.tcp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class DemoTcpServer {
    public static void main(String[] args) {
        DemoTcpServer.startServer();
    }

    public static void startServer(){
        System.out.println("TCP Server启动，监听端口8888...");
        ServerSocket serverSocket = null;
        BufferedReader reader = null;
        try {
            serverSocket = new ServerSocket(8888);
            Socket clientsocket = serverSocket.accept();
            System.out.println("客户端连接成功!");

            reader = new BufferedReader(new InputStreamReader(clientsocket.getInputStream()));
            String message = reader.readLine();
            serverSocket.close();
            System.out.println("客户端消息:"+ message);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
